import CommonBaseSchema from '#common/base_schema'

export default class extends CommonBaseSchema {
  protected tableName = 'stock_orders'

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments()
      table.integer('fk_shop_id').notNullable().unsigned().references('shops.id').comment('店铺ID')

      table
        .integer('fk_stock_method_id')
        .notNullable()
        .unsigned()
        .references('dicts.id')
        .comment('库存方式ID')

      table
        .integer('fk_warehouse_id')
        .notNullable()
        .unsigned()
        .references('dicts.id')
        .comment('仓库ID')

      table.integer('fk_member_id').nullable().unsigned().references('members.id').comment('会员ID')

      table.string('bill_no', 20).unique().comment('销售单号')
      table.dateTime('bill_date').comment('销售日期')
      table.string('bill_type', 255).comment('销售类型')
      table.string('stock_type', 255).comment('库存类型')
      table.string('stock_way', 255).comment('库存方式')
      table.string('in_order_no', 20).comment('入库单号')
      table.string('out_order_no', 20).comment('出库单号')
      table.integer('total_quantity').unsigned().defaultTo(0).comment('总数量')
      table.integer('total_amount').unsigned().defaultTo(0).comment('总价格')
      table.integer('status').unsigned().defaultTo(1).comment('状态')
      table.string('memo', 255).defaultTo('').comment('备注')

      this.defineCommonColumns(table)
      table.comment('库存订单表')
    })
  }

  async down() {
    this.schema.dropTable(this.tableName)
  }
}
